package utils

import (
	"math/rand"
)

func GetRandomFromMap[T any](ms map[string]T) (key string, v T, ok bool) {
	// map 遍历本身就是随机的! 直接取第一个
	ok = false

	// n := rand.Intn(len(ms))
	for key, v = range ms {
		ok = true
		// if n == 0 {
		return
		// }
		// n--
	}

	return

	// keys_for_video_url := [3]string{"http_hls_fmp4_avc", "http_hls_ts_avc", "http_stream_flv_avc"}
	// fmt.Printf("keys_for_video_url: %v\n", keys_for_video_url)
}

func GetRandomFromSlice[T any](ss []T) (v T, ok bool) {
	// map 遍历本身就是随机的! 直接取第一个
	if len(ss) == 0 {
		ok = false
		return
	}

	v = ss[rand.Intn(len(ss))]
	ok = true
	return

	// keys_for_video_url := [3]string{"http_hls_fmp4_avc", "http_hls_ts_avc", "http_stream_flv_avc"}
	// fmt.Printf("keys_for_video_url: %v\n", keys_for_video_url)
}
